package com.dyz.leetcode._01_array;

public class _11_maxArea {
    // 双指针，夹击
    public int maxArea(int[] height) {
        int n = height.length;
        int left = 0;
        int right = n - 1;
        int ans = 0;
        while (left < right) {
            int cur = Math.min(height[left], height[right]) * (right - left);
            ans = Math.max(ans, cur);
            if (height[left] > height[right]) {
                right--;
            } else {
                left++;
            }
        }
        return ans;
    }

    public int maxArea1(int[] height) {
        int n = height.length;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int area = Math.min(height[i], height[j]) * (j - i);
                ans = Math.max(ans, area);
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println("_11_maxArea.main()");
    }
}
